Change GtkCalendarDetailFunc to return newly allocated string. (#339540)
authorMathias Hasselmann <hasselmm@src.gnome.org>
Thu, 17 Jan 2008 16:42:04 +0000 (16:42 +0000)
committerMathias Hasselmann <hasselmm@src.gnome.org>
Thu, 17 Jan 2008 16:42:04 +0000 (16:42 +0000)
* gtk/gtkcalendar.c: Release the memory returned by the detail_func.
* gtk/gtkcalendar.h: Remove G_CONST_RETURN from GtkCalendarDetailFunc.
* tests/testcalendar.c: Duplicate calendar details before returning.

svn path=/trunk/; revision=19382

ChangeLog
gtk/gtkcalendar.c
gtk/gtkcalendar.h
tests/testcalendar.c

index c330fe275cf83c072df922c43384fc113b5fcc89..1d303b7f90ac26dfd437900c6eec5cc81dcd4af1 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2008-01-16  Mathias Hasselmann  <mathias@openismus.com>
+
+       Change GtkCalendarDetailFunc to return newly allocated string. (#339540)
+
+       * gtk/gtkcalendar.c: Release the memory returned by the detail_func.
+       * gtk/gtkcalendar.h: Remove G_CONST_RETURN from GtkCalendarDetailFunc.
+       * tests/testcalendar.c: Duplicate calendar details before returning.
+
 2008-01-16  Christian Persch  <chpe@gnome.org>
 
        * gtk/gtkwidget.c: Store the event mask and extension event mode
index b9cdfa9b9b8b3875774823cc026ff1138cd22678..269125f1dbcfa349930b4cfc6b822e372be6a8ec 100644 (file)
@@ -1672,7 +1672,7 @@ gtk_calendar_unrealize (GtkWidget *widget)
     (* GTK_WIDGET_CLASS (gtk_calendar_parent_class)->unrealize) (widget);
 }
 
-static G_CONST_RETURN gchar*
+static gchar*
 gtk_calendar_get_detail (GtkCalendar *calendar,
                          gint         row,
                          gint         column)
@@ -1709,7 +1709,7 @@ gtk_calendar_query_tooltip (GtkWidget  *widget,
 {
   GtkCalendarPrivate *priv = GTK_CALENDAR_GET_PRIVATE (widget);
   GtkCalendar *calendar = GTK_CALENDAR (widget);
-  const gchar *detail = NULL;
+  gchar *detail = NULL;
   GdkRectangle day_rect;
 
   if (priv->main_win)
@@ -1736,6 +1736,8 @@ gtk_calendar_query_tooltip (GtkWidget  *widget,
       gtk_tooltip_set_tip_area (tooltip, &day_rect);
       gtk_tooltip_set_markup (tooltip, detail);
 
+      g_free (detail);
+
       return TRUE;
     }
 
@@ -1914,7 +1916,7 @@ gtk_calendar_size_request (GtkWidget        *widget,
         for (r = 0; r < 6; r++)
           for (c = 0; c < 7; c++)
             {
-              const gchar *detail = gtk_calendar_get_detail (calendar, r, c);
+              gchar *detail = gtk_calendar_get_detail (calendar, r, c);
 
               if (detail)
                 {
@@ -1935,6 +1937,7 @@ gtk_calendar_size_request (GtkWidget        *widget,
                     max_detail_height = MAX (max_detail_height, logical_rect.height);
 
                   g_free (markup);
+                  g_free (detail);
                 }
             }
     }
@@ -2429,7 +2432,7 @@ calendar_paint_day (GtkCalendar *calendar,
   GtkCalendarPrivate *priv = GTK_CALENDAR_GET_PRIVATE (calendar);
   cairo_t *cr;
   GdkColor *text_color;
-  const gchar *detail;
+  gchar *detail;
   gchar buffer[32];
   gint day;
   gint x_loc, y_loc;
@@ -2619,6 +2622,7 @@ calendar_paint_day (GtkCalendar *calendar,
 
   g_object_unref (layout);
   cairo_destroy (cr);
+  g_free (detail);
 }
 
 static void
index 5fa887d39bb37e5f971be06990fb91742c46d748..1e6ff9d39c84c6837137a7ecc38f8fc79779f099 100644 (file)
@@ -89,13 +89,14 @@ typedef enum
  *
  * Since: 2.16
  *
- * Return value: Pango markup with details for the specified day, or %NULL.
+ * Return value: Newly allocated string with Pango markup with details
+ * for the specified day, or %NULL.
  */
-typedef G_CONST_RETURN gchar* (*GtkCalendarDetailFunc) (GtkCalendar *calendar,
-                                                        guint        year,
-                                                        guint        month,
-                                                        guint        day,
-                                                        gpointer     user_data);
+typedef gchar* (*GtkCalendarDetailFunc) (GtkCalendar *calendar,
+                                         guint        year,
+                                         guint        month,
+                                         guint        day,
+                                         gpointer     user_data);
 
 struct _GtkCalendar
 {
index d3cf08c83278b2e11bbb325e1f9b27ce017a3f9c..4e1bb8494770d3c739e87e6a8241b46e1d30ef1f 100644 (file)
@@ -85,7 +85,7 @@ calendar_set_detail (CalendarData *data,
   g_hash_table_replace (data->details_table, key, detail);
 }
 
-static G_CONST_RETURN gchar*
+static gchar*
 calendar_get_detail (CalendarData *data,
                      guint         year,
                      guint         month,
@@ -98,7 +98,7 @@ calendar_get_detail (CalendarData *data,
   detail = g_hash_table_lookup (data->details_table, key);
   g_free (key);
 
-  return detail;
+  return (detail ? g_strdup (detail) : NULL);
 }
 
 static void